package com.xrkol.sharelib.entity;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

import com.xrkol.sharelib.util.TimeUtil;

/**
 * 
 * ResponseStatusLog实体
 * 
 * @author dipei.ruan
 *
 */
@Entity
@Table
public class ResponseStatusLog {

	@Id
	@GenericGenerator(name = "hibernate-uuid", strategy = "uuid")
	@GeneratedValue(generator = "hibernate-uuid")
	private String id;

	/**
	 * 时间戳
	 */
	private Long timestamp;

	/**
	 * 日志类型
	 */
	@Enumerated(EnumType.STRING)
	private ResponseLogType logType;
 
	/**
	 * 返回json数据
	 */
	@Lob
	private String jsonData;
	
	/**
	 * 失败代码
	 */
	private int errorCode = 0;

	/**
	 * 错误信息
	 */
	private String errorMessage;

	/**
	 * 获取存储时间，利于显示
	 * 
	 * @return
	 */
	public Date getDate() {
		return TimeUtil.toDate(timestamp);
	}
	
	/**
	 * 判断是否发送成功
	 * @return
	 */
	public boolean isSuccess(){
		return !logType.equals(ResponseLogType.FAIL);
	}

	public int getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(int errorCode) {
		this.errorCode = errorCode;
	}

	public String getErrorMessage() {
		return errorMessage;
	}

	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Long getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(Long timestamp) {
		this.timestamp = timestamp;
	}

	public ResponseLogType getLogType() {
		return logType;
	}

	public void setLogType(ResponseLogType logType) {
		this.logType = logType;
	}

	public String getJsonData() {
		return jsonData;
	}

	public void setJsonData(String jsonData) {
		this.jsonData = jsonData;
	}

}
